#include "widget.h"
#include "ui_widget.h"

#include <fstream>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->comboBox->addItem("麦辣鸡腿堡");
    ui->comboBox->addItem("巨无霸");
    ui->comboBox->addItem("双重牛肉芝士汉堡");

    //我们读取文件内容，把文件的内容作为ComboBox的选项
    std::ifstream file("D:/Qt/qt/QComboBox/drink.txt");
    if(!file.is_open()){
        qDebug()<<"文件打开失败";
        return ;
    }
    //按行读取文本内容，getline
    std::string line;
    while(std::getline(file,line)){
        //取到的每一行内容设置到下拉框中
        ui->comboBox_3->addItem(QString::fromStdString(line));
    }
    file.close();
}

Widget::~Widget()
{
    delete ui;
}

